package com.exam.meituan;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution001 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(scanner.nextInt());
        }
        int len = set.size();
        int[] nums = new int[len];
        int index = 0;
        for(int num : set){
            nums[index++] = num;
        }
        Arrays.sort(nums);
        int[] dp = new int[len];
        dp[0] = 1;
        if(len == 1){
            System.out.println(1);
            return;
        }
        if(nums[1] - nums[0] > 1){
            dp[1] = 2;
        }else{
            dp[1] = 1;
        }
        for (int i = 2; i < len; i++) {
            if(nums[i] - nums[i - 1] > 1){
                dp[i] = dp[i - 1] + 1;
            }else{
                dp[i] = Math.max(dp[i - 1], dp[i - 2] + 1);
            }
        }
        System.out.println(dp[len - 1]);
    }
}
